#!/bin/bash

# default size: 1024 1024 1024 128 8

# $1: dag
function test_all_parameters() 
{
    get_exec  $1
    for N in 512 1024 2048 
    do
        for M in  512 1024 2048
        do
            for P in  512 1024 2048
            do
               for TS in  64 128 256 
                do
                    for nthreads in 1 2 4 8 
                    do
                    for((i=0;i<$num_run;i++))
                    do
                    echo $N $M $P $TS $nthreads " ">>$logfile
                    echo -n $N $M $P $TS $nthreads " ">>$outfile
                    ./matmul_$1 $N $M $P $TS $nthreads >tmp
		            grep "exec time : " tmp | awk '{print $4}' >> $outfile
		            cat tmp >>$logfile
                   done
                   done
                done
            done
        done
    done
}

#$1, dag
#$2, N
#$3, M
#$4, P
#$5, TS
function test_one_parameter() 
{
    for nthreads in 1 2 4 8
    do
        for((i=0;i<$num_run;i++))
        do
            echo $2 $3 $4 $5 $nthreads " ">>$logfile
            echo -n $2 $3 $4 $5 $nthreads " ">>$outfile
            ./matmul_$1 $2 $3 $4 $5  $nthreads >tmp
		    grep "exec time : " tmp | awk '{print $4}' >> $outfile
		    cat tmp >>$logfile
        done
    done
}
#$1, dag
function get_exec()
{
    make clean
	make $1 
}

#$1, dag
#$2, N
#$3, M
#$4, P
#$5, TS
function do_one_test()
{
    get_exec  $1 
    test_one_parameter $1 $2 $3 $4 $5
}


testcase=('matmul')
flagname=("")

lenth=${#testcase[*]}
num_run=3
for((i=0;i<$lenth;i++))
do
	dir="data"
	mkdir $dir
	curdate=$(date +%Y_%m_%d_%H_%M_%S)
    outfile="$dir/${testcase[$i]}_$curdate.txt"
    logfile="$dir/${testcase[$i]}_$curdate.log"
    do_one_test dag 1024 1024 1024 128  
    # test_all_parameters dag
done
